package com.jingbian.cppccbackend.service.impl.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jingbian.cppccbackend.entity.News;
import com.jingbian.cppccbackend.mapper.admin.adminNewsMapper;
import com.jingbian.cppccbackend.service.admin.NewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingbian.cppccbackend.entity.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 新闻表，用于存储新闻信息 服务实现类
 * </p>
 *
 * @author yezi
 * @since 2025-03-03
 */
@Service
public class adminNewsServiceImpl extends ServiceImpl<adminNewsMapper, News> implements NewsService {

    @Autowired
    adminNewsMapper adminNewsMapper;

    @Override
    public PageVO<News> getNews(Integer pageNum, Integer pageSize, String sortType, String startDate, String endDate, String searchText) {
        PageVO<News> pb = new PageVO<>();
        PageHelper.startPage(pageNum, pageSize);
        List<News> news = adminNewsMapper.getNews(sortType, startDate, endDate, searchText);
        Page<News> pag = (Page<News>) news;
        pb.setTotal(pag.getTotal());
        pb.setItems(pag.getResult());
        return pb;
    }

    @Override
    public void delete(Integer nid) {
        adminNewsMapper.delete(nid);
    }

    @Override
    public void updateNews(Integer nid, News news) {
        adminNewsMapper.updateNews(nid, news);
    }


}
